package com.tnsw.facebookautoliker.dialog;

import com.tnsw.coreutils.MyLog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class LogoutDialog extends android.support.v4.app.DialogFragment {
	
	private String tag = "LogoutDialog";
	private AlertDialog.Builder builder;
	private MyDialogOnClickListener onClickListener;
	private LogoutDialog self;
		
	@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
		this.self = this;
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		
		builder.setTitle("Logout");
		builder.setMessage("Are you sure to logout and clear history?");
		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				MyLog.d(tag, "position(which)=" + which);
				onClickListener.onClick(self, which);
			}
		});
		
		builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				MyLog.d(tag, "negative(which)=" + which);
				onClickListener.onClick(self, which);
				
			}
		});
		
		return(builder.create());
	}
	
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		
		if (activity instanceof MyDialogOnClickListener) {
			this.onClickListener = (MyDialogOnClickListener) activity;
			MyLog.d(tag, "Set MyDialogOnClickListener to Activity=" + activity.getClass().getName());
		} else {
			MyLog.w(tag, "Not found MyDialogOnClickListener implemented with Activity=" + activity.getClass().getName());
		}
	}
	
	public AlertDialog.Builder getBuilder() {
		return(this.builder);
	}

}
